package com.fm.controller;

import com.fm.entity.ProductTopic;
import com.fm.entity.RuleDestination;
import com.fm.service.ProductService;
import com.fm.service.ProductTopicService;
import com.fm.service.RuleDestinationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.print.attribute.standard.Destination;
import java.util.Map;

/**s
 * Created by Administrator on 2018/7/30 0030.
 */
@RestController
@RequestMapping("/api/ruleDestination")
public class RuleDestinationController extends MBaseController<RuleDestination, RuleDestinationService>{

    @Autowired
    ProductService productService;
    @Autowired
    ProductTopicService productTopicService;

    @Override
    public RuleDestination beforeList(Map t) {
        RuleDestination ruleDestination = new RuleDestination();
        ruleDestination.setRuleId(Integer.parseInt((String) t.get("id")));
        return ruleDestination;
    }

    @Override
    public void afterList(Page<RuleDestination> page) {
        for (RuleDestination destination : page.getContent()) {
            if (destination.getTopicId()!= null)
                destination.setTopic(productTopicService.selectOneByExample(destination.getTopicId()).get().getValue());
        }
    }
}
